$(function(){
	var timeall=10,timeji,timestatus = true,telsure = true;
	$('.nyan').click(function(){
		telsure = true;
		$('.tel').each(function(){
			var tel = /^1[0-9]{10}$/
			if(!tel.test($(this).val())){
				$(this).css({'border':'solid 1px #f00'});
				alert('请输入正确的手机号码');
				telsure = false;
				return false;
			};
		})
		if(!timestatus||!telsure){
			return false;
		}
		var oldphone = $('.telold').val();
		var newphone = $('.telnew').val();
		$.post(config.url,{oldphone:oldphone,newphone:newphone},function(res){
			if(res.status==1){
				timestatus = false;
				$('.nyan').val('发送验证码（'+timeall+'）').css({
					'font-size':"12px",
					'background': '#bbb'
				});
			    timeji = setInterval(function(){
					time();
				},1000);
			}else{
				alert(res.message);
			}
		},'json')
	})
	function time(){
		timeall--;
		$('.nyan').val('发送验证码（'+timeall+'）');
		if (timeall==0) {
			$('.nyan').val('获取验证码').css({
			'font-size':"14px",
			'background': '#ddd'
			});
			clearInterval(timeji);
			timeall = 10;
			timestatus = true;
		};
	}
	
})